package com.liaoct.lct.listener;

import java.util.List;
import java.util.Map;

import com.liaoct.lct.activity.BaseActivity;
import com.liaoct.lct.adapter.ContactListViewAdapter;
import com.liaoct.lct.db.DataBaseManagement;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ListView;

/**
 * 对联系人搜索框内容变化监听类
 * 
 * @author liaoct
 * 
 */
public class ContactSearchEditTextChangeListener implements TextWatcher {

	private ListView listView;

	private BaseActivity activity;

	private DataBaseManagement db;

	public ContactSearchEditTextChangeListener(Context context,
			ListView listView) {
		this.activity = (BaseActivity) context;
		this.listView = listView;
		db = DataBaseManagement.newInstance(this.activity);
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		List<Map<String, Object>> list = db.queryContactList(s.toString());
		ContactListViewAdapter adapter = (ContactListViewAdapter)listView.getAdapter();
		adapter.refresh(list);
	}

	@Override
	public void afterTextChanged(Editable s) {

	}

}
